package com.mzj.saas.mservice.property.controller;

import com.mzj.saas.annotation.RepeatSubmit;
import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.property.service.ComplainSuggestReplyService;
import com.mzj.saas.mservice.property.vo.ComplainSuggestReplyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 投诉建议回复
 *
 * @author hikari
 * @since 2021-05-13
 */
@RestController
@RequestMapping("/property/complainSuggestReply")
public class ComplainSuggestReplyController {
    @Autowired
    private ComplainSuggestReplyService complainSuggestReplyService;

    /**
     * 回复列表
     *
     * @param complainSuggestId
     * @param pageNumber
     * @param pageSize
     * @param deviceType 设备类型 1 小程序  2 PC端
     * @return
     */
    @GetMapping("/{complainSuggestId}")
    public ResultBean<ApiData<ComplainSuggestReplyVO>> listByComplainSuggestId(@PathVariable Long complainSuggestId,
                                                                               @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                               @RequestParam(defaultValue = "5") Integer pageSize,
                                                                               @RequestParam(value = "deviceType", required = false) Integer deviceType) {
        return complainSuggestReplyService.findByComplainSuggestId(complainSuggestId, pageNumber, pageSize, deviceType);
    }

    /**
     * 回复
     *
     * @param accessToken
     * @param complainSuggestReplyVO
     * @return
     */
    @PostMapping
    @RepeatSubmit
    public ResultBean<ComplainSuggestReplyVO> save(@RequestHeader String accessToken,
                                                   @RequestBody ComplainSuggestReplyVO complainSuggestReplyVO) {
        return complainSuggestReplyService.save(accessToken, complainSuggestReplyVO);
    }

    /**
     * 验证回复次数
     *
     * @param accessToken
     * @param type
     * @param complainSuggestId
     * @return
     */
    @GetMapping("/verifyReply")
    public ResultBean<Object> verifyReply(@RequestHeader String accessToken,
                                          @RequestParam(value = "type") Integer type,
                                          @RequestParam(value = "complainSuggestId") Long complainSuggestId) {
        return complainSuggestReplyService.verifyReply(accessToken, type, complainSuggestId);
    }


}
